package org.bookshare.document.reader;

import java.io.File;
import java.io.IOException;

import org.bookshare.document.beans.DocumentType;

/**
 * Helper for DocumentReader implementations.
 * @author Reuben Firmin
 *
 * @param <T> The type of documents this reader can handle
 */
public abstract class AbstractReader<T extends DocumentType> {

    private File tmpDir;

    /**
     * Set the temporary working directory for this reader.
     * @param tmpDir the tmpDir. Will be created if doesn't exist
     * @throws IOException if file access fails
     */
    public final void setTmpDir(final String tmpDir)
    	throws IOException
    {
    	final File file = new File(tmpDir);
        if (file.exists()) {
            if (!file.isDirectory()) {
                throw new IOException("TmpDir must be a valid folder");
            }
        } else {
            file.mkdirs();
        }
        this.tmpDir = file;
    }

    /**
     * The tmp dir.
     * @return The tmp dir.
     */
    protected final File getTmpDir() {
        return tmpDir;
    }
}
